<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改合同管理')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-contract-edit" th:object="${crmContract}">
            <input name="contractId" th:field="*{contractId}" type="hidden">
            <input name="customerId" type="hidden" id="customerId"  th:field="*{customerId}"/>
            <input name="orderId" th:field="*{orderId}" type="hidden" id="orderId" />
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">合同名称：</label>
                <div class="col-sm-8">
                    <input name="contractName" th:field="*{contractName}" class="form-control" type="text" required>
                </div>
            </div>            
            <div class="form-group">    
                <label class="col-sm-3 control-label">合同编号：</label>
                <div class="col-sm-8">
                    <input name="contractNo" th:field="*{contractNo}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">客户名称：</label>
                <div class="col-sm-8">                    
                    <div class="input-group">                     	
	                    <input name="customerName"  onclick="selectCustomer()" th:field="*{customer.customerName}" class="form-control" type="text" placeholder="请选择所属客户 " id="customerName" required readonly>
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>	
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">成交订单：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                   		<input name="orderName"  id="orderName" onclick="selectOrder()"  th:field="*{order.orderName}" class="form-control" type="text" placeholder="请选择成交订单 " readonly>
                   		<span class="input-group-addon"><i class="fa fa-search"></i></span>
                   	</div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">合同类型：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('contract_type')}">
                        <input type="radio" th:id="${'contractType_' + dict.dictCode}" name="contractType" th:value="${dict.dictValue}" th:field="*{contractType}" required>
                        <label th:for="${'contractType_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>            
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">合同金额：</label>
                <div class="col-sm-8">
                    <input id="totalMoney" name="totalMoney" th:field="*{totalMoney}" class="form-control" type="number" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">合同签署日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="signDate" th:value="${#dates.format(crmContract.signDate, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">合同开始日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="dateStart" th:value="${#dates.format(crmContract.dateStart, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">合同结束日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="dateEnd" th:value="${#dates.format(crmContract.dateEnd, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label" is-required>合同签署人：</label>
                <div class="col-sm-8">
                    <div class="input-group">
	                    <input name="signBy" onclick="selectUser()" id="signBy" th:field="*{signBy}" type="text" placeholder="请选择合同签署人 " class="form-control" required readonly>
	                	<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
        	<button type="button" class="btn btn-sm btn-primary" onclick="submit()" shiro:hasPermission="crm:contract:submit"><i class="fa fa-location-arrow"></i>提 交</button>&nbsp;
            <button type="button" class="btn btn-sm btn-success" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "crm/contract";
        $("#form-contract-edit").validate({
            focusCleanup: true
        });
        
        function submit() {
        	$.modal.confirm("确认提交吗？", function() {
        		if ($.validate.form()) {        			
        			/*var totalMoney=parseFloat($("input[name='totalMoney']").val());
        			var payedMoney=parseFloat($("input[name='payedMoney']").val());
                	if(payedMoney>totalMoney){
            			$.modal.alertWarning("已收款不能大于总金额！");
                		return;
            		}    */
                    $.operate.saveTab(prefix + "/submit", $('#form-contract-edit').serialize());
                }
        	});
            
        }

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.saveTab(prefix + "/edit", $('#form-contract-edit').serialize());
            }
        }

        $("input[name='dateStart']").datetimepicker({
    		format: 'yyyy-mm-dd',
    		minView: "month",
    	    todayBtn:  true,
    	    autoclose: true
    	}).on('changeDate', function(event) {
    		event.preventDefault();
    		event.stopPropagation();
    		var startTime = event.date;
    		$("input[name='dateEnd']").datetimepicker('setStartDate', startTime);
    	});
    	
    	$("input[name='dateEnd']").datetimepicker({
    		format: 'yyyy-mm-dd',
    		minView: "month",
    		todayBtn:  true,
    		autoclose: true
    	}).on('changeDate', function(event) {
    		event.preventDefault();
    		event.stopPropagation();
    		var endTime = event.date;
    		$("input[name='dateStart']").datetimepicker('setEndDate', endTime);
    	});
    	
    	$("input[name='signDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
    <script src="../static/crm/customer.js" th:src="@{/crm/common.js}"></script>
</body>
</html>